/*
 * Created on Jul 25, 2005
 *
 */
package com.erclab.internal.xpresso.unittests;

import com.erclab.internal.xpresso.Application;
import com.erclab.internal.xpresso.ReportFactory;
import com.erclab.internal.xpresso.conf.Settings;
import com.erclab.internal.xpresso.exceptions.ApplicationException;
import com.erclab.internal.xpresso.exceptions.DirectoryException;
import com.erclab.internal.xpresso.reports.Report;
import com.erclab.internal.xpresso.reports.ReportParameters;
import com.erclab.internal.xpresso.reports.ReportResultSet;
import com.erclab.internal.xpresso.security.User;

import junit.framework.TestCase;

/**
 * @author Enrique Rodriguez.
 *
 */
public class PagingTest extends TestCase {

	Application xpresso = null;
	User user = null;

	/**
	 * Constructor for PagingTest.
	 * @param arg0
	 */
	public PagingTest(String arg0) {
		super(arg0);
	}

	protected void setUp() throws Exception {
		super.setUp();
		try {
			xpresso = new Application();
		} catch(ApplicationException e){
			fail("Create Application failed: " + e.toString());
		}
		try {
			user = new User();
			Settings.getUserDirectory().loadUserBean(user);
		} catch (DirectoryException e) {
			fail();
			e.printStackTrace();
		}
	}

	public void testCreateReport(){
		ReportParameters parameters = new ReportParameters();
		parameters.setConditions("");
		parameters.setPageNum("1");
		parameters.setParentKeyValue(null);
		parameters.setUniqueKeyValue("1");
		parameters.setUser(user);

		
		Report theReport = null;
		try {
			theReport = ReportFactory.loadReport("Reports");
		} catch (Exception e1) {
			e1.printStackTrace();
			fail();
		}
		
		// Load the parameters of the report
		theReport.setReportParameters(parameters);
		
		ReportResultSet rrs = null;
		try {
			rrs = ReportFactory.executeReportQuery(theReport);
		} catch (Exception e) {
			e.printStackTrace();
			fail();
		}
		
		// Print result set:
		assertTrue(rrs != null);
		for (int i =0; i < rrs.getNumberOfColumns(); i++){
			System.out.print(rrs.getHeaderText(i) + " | ");
		}
		while(rrs.nextRow()){
			System.out.println("");
			for (int i =0; i < rrs.getNumberOfColumns(); i++){
				System.out.print(rrs.getRowValue(i) + " | ");
			}			
		}
	}


}
